﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Sale_and_manage
{
    class Validate
    {

        /// <summary>
        /// Kiểm tra tính đúng đắn của số điện thoại
        /// </summary>
        /// <param name="Number"></param>
        /// <returns></returns>
        public Boolean PhoneNumber(string Number)
        {
            if ((Number.Length == 10) || (Number.Length == 11))
            {
                return true;
            }
            else
                return false;
        } 

        /// <summary>
        /// Kiểm tra tính đúng đắn của email
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public Boolean Email(string email)
        {
            try
            {
                MailAddress m = new MailAddress(email);
                return true;
            }
            catch (FormatException)
            {
                return false;
            }
        }

        /// <summary>
        /// Kiểm tra mã vạch
        /// 7: mã hóa đơn
        /// 9: mã khách hàng
        /// 10: mã ISBN
        /// 13: mã ISBN
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Boolean Barcode(string code)
        {
            if (code.Length == 7 || code.Length == 9 || code.Length == 10 || code.Length == 13)
            {
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// Kiem tra tinh dung dan cua Chiet khau
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public Boolean Discount(int number)
        {
            if (number > 0 && number < 100)
            {
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// Kiem tra tinh dung dan ngay sinh
        /// </summary>
        /// <param name="birth"></param>
        /// <returns></returns>
        public Boolean Birthday(DateTime birth)
        {
            if (birth.Year < DateTime.Now.Year)
            {
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// Kiem tra hop le ten chi bao gom a-z A-Z va backspase
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Boolean Name(string name)
        {
            Regex Nameregex = new Regex(@"[^a-zA-Z\sáàạảãâấầậẩẫăắằặẳẵÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴéèẹẻẽêếềệểễÉÈẸẺẼÊẾỀỆỂỄóòọỏõôốồộổỗơớờợởỡÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠúùụủũưứừựửữÚÙỤỦŨƯỨỪỰỬỮíìịỉĩÍÌỊỈĨđĐýỳỵỷỹÝỲỴỶỸ]");
            Match match = Nameregex.Match(name);
            if (match.Success)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// check only ISBN
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Boolean ISBN(string code)
        {
            if (code.Length >= 10 && code.Length <= 13)
            {
                return true;
            }
            else
                return false;
        }
    }
}
